package com.fmy.jurisdiction.modular.wrapper.obj;

import com.fmy.jurisdiction.core.commons.factory.ConstantFactory;
import com.fmy.jurisdiction.modular.model.vo.AdminRoleChildren;
import com.fmy.jurisdiction.modular.wrapper.ObjectWrapper;

import java.util.List;

/**
 * @author Mr.fmy
 * @version 1.0.0
 * @ClassName AdminRoleWrapper
 * @Description TODO 管理员角色 Wrapper类
 * @createTime 2019/9/18 14:02
 */
public class AdminRoleWrapper extends ObjectWrapper {

    public AdminRoleWrapper(Object obj) {
        super(obj);
    }

    @Override
    protected void wrp(Object t) {
        if (t instanceof AdminRoleChildren) {
            AdminRoleChildren children = (AdminRoleChildren) t;
            children.setCreateUserName(ConstantFactory.me().getUserName(children.getCreateUser()));
            children.setCreateUser(null);
            recursion(children.getChildren());
        }
    }

    private void recursion(List<AdminRoleChildren> children) {
        if (children != null) {
            children.forEach(item -> {
                item.setCreateUserName(ConstantFactory.me().getUserName(item.getCreateUser()));
                item.setCreateUser(null);
                recursion(item.getChildren());
            });
        }
    }
}
